package cn.px.rest.controller.workplace;

import cn.px.common.bean.AbstractPageResultBean;
import cn.px.common.util.R;
import cn.px.dao.bean.MyVOPage;
import cn.px.dao.dto.workplace.WorkplaceBacklogDTO;
import cn.px.dao.dto.workplace.WorkplaceBacklogUserDTO;
import cn.px.dao.entity.workplace.WorkplaceBacklog;
import cn.px.dao.vo.query.workplace.WorkplaceBacklogUserVO;
import cn.px.service.workplace.WorkplaceBacklogService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 待办事项 控制器
 * @author 品讯科技
 * @date 2024-08
 * @Version Copyright (c) 2019,北京乾元坤和科技有限公司 All rights reserved.
 */
@RestController
@AllArgsConstructor
@RequestMapping("/workplace/backlogs")
public class WorkplaceBacklogController {

    private final WorkplaceBacklogService workplaceBacklogService;

    /**
     * 通过id查询单条记录
     *
     * @param id 主键
     * @return R
     */
    @GetMapping("/{id}")
    public R<WorkplaceBacklog> getById(@PathVariable("id") String id) {
        return new R<>(workplaceBacklogService.getModelById(id));
    }


    /**
     * 通过id查询单条记录
     *
     * @param logId 主键
     * @return R
     */
    @GetMapping("/user/{logId}")
    public R<WorkplaceBacklogUserVO> getUserVOById(@PathVariable("logId") String logId) {
        return new R<>(workplaceBacklogService.getUserVOById(logId));
    }

//  /**
//   * 新增记录
//   *
//   * @param workplaceBacklogDTO 待办事项DTO
//   * @return R
//   */
//  @SysLog("新增待办事项")
//  @PostMapping
//  @PreAuthorize("@pms.hasPermission('workplace-backlogs-add')")
//  public R save(@Validated({AddGroup.class}) @RequestBody WorkplaceBacklogDTO workplaceBacklogDTO) {
//      return new R<>(workplaceBacklogService.saveModelByDTO(workplaceBacklogDTO));
//  }


//    /**
//     * 通过id删除一条记录
//     *
//     * @param id 主键
//     * @return R
//     */
//    @SysLog("删除待办事项")
//    @DeleteMapping("/{id}")
//    @PreAuthorize("@pms.hasPermission('workplace-backlogs-del')")
//    public R removeById(@PathVariable String id) {
//        workplaceBacklogService.deleteByPrimaryKey(id);
//        return new R<>();
//    }

//    /**
//     * 批量记录
//     *
//     * @param ids 主键
//     * @return R
//     */
//    @SysLog("批量删除待办事项")
//    @DeleteMapping("")
//    @PreAuthorize("@pms.hasPermission('workplace-backlogs-del')")
//    public R removeIds(@RequestBody List<String> ids) {
//        workplaceBacklogService.batchDelete(ids);
//        return new R<>();
//    }
    /**
     * 修改记录
     *
     * @return R
     */
    @PutMapping("/{id}")
    public R update(@PathVariable("id") String id) {
        workplaceBacklogService.updateStatusByUser(id);
        return new R<>();
    }

    /**
     * 获取分页
     *
     * @param pageNum             当前页码
     * @param pageSize            每页条数
     * @param workplaceBacklogDTO 待办事项DTO
     * @return R
     */
    @GetMapping("/page")
    public R<AbstractPageResultBean<WorkplaceBacklog>> query(WorkplaceBacklogDTO workplaceBacklogDTO, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "20") int pageSize) {
        return new R<>(workplaceBacklogService.selectPageInfo(workplaceBacklogDTO, pageNum, pageSize));
    }


    /**
     * 获取分页
     *
     * @param pageNum  当前页码
     * @param pageSize 每页条数
     * @param model    待办事项DTO
     * @return R
     */
    @GetMapping("/user/page")
    public R<MyVOPage<WorkplaceBacklogUserVO>> query(WorkplaceBacklogUserDTO model,
                                                     @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "20") int pageSize) {
        return new R<>(workplaceBacklogService.selectByUserPage(model, pageNum, pageSize));
    }

//    /**
//     * 获取列表
//     *
//     * @param workplaceBacklogDTO 待办事项DTO
//     * @return R
//     */
//    @GetMapping("")
//    public R query(WorkplaceBacklogDTO workplaceBacklogDTO) {
//        return new R<>(workplaceBacklogService.getModelListByDTO(workplaceBacklogDTO));
//    }

//    /**
//     * 待办事项导出
//     *
//     * @param workplaceBacklogDTO 待办事项DTO
//     * @return R
//     */
//    @GetMapping("/export")
//    @SysLog("待办事项导出")
//    @PreAuthorize("@pms.hasPermission('workplace-backlogs-export')")
//    public void export(HttpServletResponse response, WorkplaceBacklogDTO workplaceBacklogDTO) {
//        List<WorkplaceBacklog> list = workplaceBacklogService.getModelListByDTO(workplaceBacklogDTO);
//        ExcelUtil.exportResponseDict(response, ExportWorkplaceBacklogVO.class, BeanConverterUtil.copyListProperties(list, ExportWorkplaceBacklogVO.class), "待办事项");
//    }

}
